package game.Engine.Entity;

import java.awt.Point;

import game.display.Animation;
import game.display.Images;

public class PowerUp extends Entity {
	private Type type;
	private int typeInt;
	private transient Animation anim;
	
	public enum Type{
		AIR,WATER,FIRE,EARTH,LIGHTNING,DOUBLEJUMPPOWER,HEALTH
	}
	
	public PowerUp(Point p, int i){
		super((double)p.getX(), (double)p.getY(), getPowerUp(i));
		this.typeInt = i;
		this.state = State.NORMAL;
		setType(i);
	}
	
	private void setType(int i){
		if(i == 0) type = Type.EARTH;
		else if(i == 1) type = Type.FIRE;
		else if(i == 2) type = Type.LIGHTNING;
		else if(i == 3) type = Type.WATER;
		else if(i == 4) type = Type.HEALTH; 
		else type = Type.DOUBLEJUMPPOWER;
	}

	public void die() {
	   this.state = State.DEAD;
	}
	private static Animation getPowerUp(int rand) {
		if(rand == 0) return Images.GREENPOWERUP.image();
		else if(rand == 1) return Images.FIREPOWERUP.image();
		else if(rand == 2) return Images.LIGHTNINGPOWERUP.image();
		else if(rand == 3) return Images.WATERPOWERUP.image();
		else if(rand == 4) return Images.HEALTH.image();
		else return Images.DOUBLEJUMPPOWERUP.image();
	}
	public void updateImage(){
		if (anim == null){
			gi = anim = getPowerUp(typeInt);
		}
		else{
			gi = anim;
		}
	}
	
	@Override 
	public void update(long timeElapsed) {
		super.update(timeElapsed);
	}
	public void handleCollision(Entity e) {
	   die();
	}
	
	public Type getType(){
		return type;
	}
	
	 public void matchWith(PowerUp p){
			z = p.getZ();
			x = p.getX();
			y = p.getY();
			dx = p.getVelocityX();
			dy = p.getVelocityY();
			state = p.getState();
			type = p.getType();
			typeInt = p.getTypeInt();
	 }
	 
	 public int getTypeInt(){
		 return typeInt;
	 }
}
